#ifndef __KEYPAD_H__
#define __KEYPAD_H__

#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#define KEYPAD_NO_PRESSED					(uint8_t)0xFF

#define KEYPAD_ROW_1_LOW					GPIO_ResetBits(GPIOD, GPIO_Pin_1);
#define KEYPAD_ROW_1_HIGH					GPIO_SetBits(GPIOD, GPIO_Pin_1);

#define KEYPAD_ROW_2_LOW					GPIO_ResetBits(GPIOD, GPIO_Pin_4);
#define KEYPAD_ROW_2_HIGH					GPIO_SetBits(GPIOD, GPIO_Pin_4);

#define KEYPAD_ROW_3_LOW					GPIO_ResetBits(GPIOE, GPIO_Pin_2);
#define KEYPAD_ROW_3_HIGH					GPIO_SetBits(GPIOE, GPIO_Pin_2);

#define KEYPAD_ROW_4_LOW					GPIO_ResetBits(GPIOD, GPIO_Pin_3);
#define KEYPAD_ROW_4_HIGH					GPIO_SetBits(GPIOD, GPIO_Pin_3);

#define KEYPAD_ROW_HIGH_BUT_1 \
{\
	KEYPAD_ROW_1_LOW;\
	KEYPAD_ROW_2_HIGH;\
	KEYPAD_ROW_3_HIGH;\
	KEYPAD_ROW_4_HIGH;\
}

#define KEYPAD_ROW_HIGH_BUT_2 \
{\
	KEYPAD_ROW_1_HIGH;\
	KEYPAD_ROW_2_LOW;\
	KEYPAD_ROW_3_HIGH;\
	KEYPAD_ROW_4_HIGH;\
}

#define KEYPAD_ROW_HIGH_BUT_3 \
{\
	KEYPAD_ROW_1_HIGH;\
	KEYPAD_ROW_2_HIGH;\
	KEYPAD_ROW_3_LOW;\
	KEYPAD_ROW_4_HIGH;\
}

#define KEYPAD_ROW_HIGH_BUT_4 \
{\
	KEYPAD_ROW_1_HIGH;\
	KEYPAD_ROW_2_HIGH;\
	KEYPAD_ROW_3_HIGH;\
	KEYPAD_ROW_4_LOW;\
}

#define KEYPAD_COLUMN_1_CHECK			GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_0)
#define KEYPAD_COLUMN_2_CHECK			GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_15)
#define KEYPAD_COLUMN_3_CHECK			GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_8)
#define KEYPAD_COLUMN_4_CHECK			GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_7)

typedef enum 
{
	KEYPAD_Button_0 = 0x00,                     /*!< Button 0 code */
	KEYPAD_Button_1 = 0x01,                     /*!< Button 1 code */
	KEYPAD_Button_2 = 0x02,                     /*!< Button 2 code */
	KEYPAD_Button_3 = 0x03,                     /*!< Button 3 code */
	KEYPAD_Button_4 = 0x04,                     /*!< Button 4 code */
	KEYPAD_Button_5 = 0x05,                     /*!< Button 5 code */
	KEYPAD_Button_6 = 0x06,                     /*!< Button 6 code */
	KEYPAD_Button_7 = 0x07,                     /*!< Button 7 code */
	KEYPAD_Button_8 = 0x08,                     /*!< Button 8 code */
	KEYPAD_Button_9 = 0x09,                     /*!< Button 9 code */
	KEYPAD_Button_STAR = 0x0A,                  /*!< Button START code */
	KEYPAD_Button_HASH = 0x0B,                  /*!< Button HASH code */
	KEYPAD_Button_A = 0x0C,	                   /*!< Button A code. Only on large size */
	KEYPAD_Button_B = 0x0D,	                   /*!< Button B code. Only on large size */
	KEYPAD_Button_C = 0x0E,	                   /*!< Button C code. Only on large size */
	KEYPAD_Button_D = 0x0F,	                   /*!< Button D code. Only on large size */
	KEYPAD_Button_NOPRESS = KEYPAD_NO_PRESSED
} KEYPAD_Button_t;

static inline char *stringFromKeypadButton(KEYPAD_Button_t key)
{
    static char *strings[] = { 	"0", "1", "2", "3",
																"4", "5", "6", "7",
																"8", "9", "*", "#",
																"A", "B", "C", "D"
														};

    return strings[key];
}

uint8_t KEYPAD_READ(void);
void KEYPAD_Init(void);
void KEYPAD_INT_PullDownRow(uint8_t row);
uint8_t KEYPAD_INT_CheckColumn(uint8_t row);
uint8_t PassworldInput(void);

void changePassword(void);
#endif

